# 编译阶段
FROM maven:3-jdk-11-slim AS builder
COPY . /project
# 添加Maven设置，添加阿里云mirror或自定义私有mirror
COPY settings.xml /usr/share/maven/conf/settings.xml
WORKDIR /project
# 执行时挂载cache，到m2目录，加快下次构建
RUN --mount=type=cache,id=m2,target=/root/.m2 /usr/bin/mvn clean package

# 构建spring镜像
FROM openjdk:11-jdk-slim
ENV LANG en_US.utf8
ENV LC_ALL en_US.utf8
COPY --from=builder /project/target/spring-boot-helloworld-*.jar /project/spring-boot-helloworld.jar
WORKDIR /project
ENTRYPOINT ["java", "-jar", "spring-boot-helloworld.jar"]
